package xhwl.insurance.db;


import android.content.Context;

import com.lidroid.xutils.DbUtils;
import com.lidroid.xutils.db.sqlite.Selector;
import com.lidroid.xutils.exception.DbException;

import java.util.ArrayList;
import java.util.List;

import xhwl.android.common.util.StringUtil;
import xhwl.insurance.db.bean.SaleInfo;


/**
* 升级模块数据库操作类
* @author lim
* @date 2017年2月9日
* @version 1.0
*/
public class SaleInfoDao extends BaseDao<SaleInfo> {

    public SaleInfoDao(Context context) {
        super(context, DbConstant.SaleInfo.DB_NAME, DbConstant.SaleInfo.DB_VERSION);
        // TODO Auto-generated constructor stub
    }
    @Override
	public void onUpgrade(DbUtils db, int oldVersion, int newVersion) {
//        if(oldVersion==1&&newVersion==2){
//            try {
//                db.execNonQuery("alter table "+DbConstant.Upgrade.DB_NAME+" add "+DbConstant.Upgrade.COLUMN_FORCE_FLAG+" text default 0");
//            } catch (DbException e) {
//                e.printStackTrace();
//            }
//
//        }
    }
    @Override
    public SaleInfo find(String memberId) {
        // TODO Auto-generated method stub
//        SaleInfo record = null;
//        if (!StringUtil.isEmpty(versionCode)) {
//            try {
//                record = db.findFirst(Selector.from(Upgrade.class).where(
//                        DbConstant.Upgrade.COLUMN_VERSION_CODE, "=", versionCode)
//                        .and(DbConstant.Upgrade.COLUMN_DOWNLOAD_STATE,"=", UpgradeEvent.STATE_COMPLETE));
//            } catch (DbException e) {
//                // TODO Auto-generated catch block
//                e.printStackTrace();
//            }
//        }
//        if (record == null) {
//            record=new SaleInfo();
//        }
//        return record;
        return null;
    }
    public List<SaleInfo> findAllFailed(String memberId){
        List<SaleInfo> list=new ArrayList<>();
        if (!StringUtil.isEmpty(memberId)) {
            try {
                list = db.findAll(Selector.from(SaleInfo.class).where(
                                DbConstant.SaleInfo.COLUMN_MEMBER_ID, "=", memberId)
                        .and(DbConstant.SaleInfo.COLUMN_STATUS,"=", SaleInfo.Status.FAIL.ordinal()));
            } catch (DbException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                list=new ArrayList<>();
            }
        }
        return list;
    }
}

